package com.czy.owner.ui.order;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.WorkOrderDetailsModel;
import com.czy.owner.ui.BaseActivity;
import com.czy.owner.ui.workorder.EvaluateActivity2;
import com.czy.owner.ui.workorder.OrderDetailsActivity3;
import com.czy.owner.ui.workorder.SeeEvaluateActivity2;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.utils.TimeUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hedepu on 2017-09-04
 */

public class OrderProcedureActivity extends BaseActivity {

    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.tv_order_num)
    TextView tvOrderNum;
    @BindView(R.id.linear_order_num)
    LinearLayout linearOrderNum;
    @BindView(R.id.tv_order_service_time)
    TextView tvOrderServiceTime;
    @BindView(R.id.linear_order_service_time)
    LinearLayout linearOrderServiceTime;
    @BindView(R.id.tv_order_service_success_time)
    TextView tvOrderServiceSuccessTime;
    @BindView(R.id.linear_order_service_success_time)
    LinearLayout linearOrderServiceSuccessTime;
    @BindView(R.id.tv_order_car)
    TextView tvOrderCar;
    @BindView(R.id.linear_order_car)
    LinearLayout linearOrderCar;
    @BindView(R.id.tv_order_commodity_project)
    TextView tvOrderCommodityProject;
    @BindView(R.id.linear_order_commodity_project)
    LinearLayout linearOrderCommodityProject;
    @BindView(R.id.tv_order_time)
    TextView tvOrderTime;
    @BindView(R.id.linear_order_time)
    LinearLayout linearOrderTime;
    @BindView(R.id.tv_order_custom_commodity_project)
    TextView tvOrderCustomCommodityProject;
    @BindView(R.id.linear_order_custom_commodity_project)
    LinearLayout linearOrderCustomCommodityProject;
    @BindView(R.id.tv_order_meassage)
    TextView tvOrderMeassage;
    @BindView(R.id.linear_order_meassage)
    LinearLayout linearOrderMeassage;
    @BindView(R.id.linear_order_cancle_time)
    LinearLayout linearOrderCancleTime;
    @BindView(R.id.tv_order_cancle_time)
    TextView tvOrderCancleTime;
    @BindView(R.id.tv_store_name)
    TextView tvStoreName;

    private WorkOrderDetailsModel workOrderDetailsModel;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_order_procedure;
    }

    @Override
    protected void initInjector() {
        workOrderDetailsModel = (WorkOrderDetailsModel) getIntent().getSerializableExtra("orderDetails");
    }

    @Override
    protected void initViews() {
//         linearOrderNum; 预约号
//        linearOrderTime 预约时间
//         linearOrderServiceTime; 开单时间
//         linearOrderServiceSuccessTime;完工时间
//         linearOrderCar; 服务车辆
//         linearOrderCommodityProject; 预约项目
//         linearOrderCustomCommodityProject; 自定义项目
//         linearOrderMeassage; 留言
        //服务中
        if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.INSERVICE) || workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.ININSPECTION)) {
            linearOrderServiceSuccessTime.setVisibility(View.GONE);
            linearOrderCommodityProject.setVisibility(View.GONE);
            linearOrderCustomCommodityProject.setVisibility(View.GONE);
            //待付余款
        } else if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.INSETTLEMENT)) {
            linearOrderCommodityProject.setVisibility(View.GONE);
            linearOrderCustomCommodityProject.setVisibility(View.GONE);
            //待评价
        } else if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.COMPLETED)) {
            linearOrderCommodityProject.setVisibility(View.GONE);
            linearOrderCustomCommodityProject.setVisibility(View.GONE);
            // 已评价commented
        } else if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.COMMENTED)) {
            linearOrderCommodityProject.setVisibility(View.GONE);
            linearOrderCustomCommodityProject.setVisibility(View.GONE);

        } else if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.CANCELLED)) {
            linearOrderCancleTime.setVisibility(View.VISIBLE);
            tvOrderCancleTime.setText(TimeUtils.timeStamp2Date(workOrderDetailsModel.getCancelTime(), "yyyy-MM-dd HH:mm"));
            linearOrderCommodityProject.setVisibility(View.GONE);
            linearOrderCustomCommodityProject.setVisibility(View.GONE);
            linearOrderServiceSuccessTime.setVisibility(View.GONE);
            if (StringUtils.isEmpty(workOrderDetailsModel.getStoreBookingNumber())) {
                linearOrderNum.setVisibility(View.GONE);
                linearOrderTime.setVisibility(View.GONE);
                linearOrderServiceSuccessTime.setVisibility(View.GONE);
                linearOrderMeassage.setVisibility(View.GONE);

            }
        }
        toolbarTitle.setText("工单流程");
        if (workOrderDetailsModel.getStoreBookingNumber() != null && !StringUtils.isEmpty(workOrderDetailsModel.getStoreBookingNumber())) {
            if (linearOrderNum.getVisibility() == View.GONE)
                linearOrderNum.setVisibility(View.VISIBLE);

            tvOrderNum.setText(workOrderDetailsModel.getStoreBookingNumber());
        } else {
            if (linearOrderNum.getVisibility() == View.VISIBLE)
                linearOrderNum.setVisibility(View.GONE);
            linearOrderMeassage.setVisibility(View.GONE);
            linearOrderTime.setVisibility(View.GONE);
        }
        if (!StringUtils.isEmpty(workOrderDetailsModel.getOpenTime())) {
            tvOrderServiceTime.setText(TimeUtils.timeStamp2Date(workOrderDetailsModel.getOpenTime(), "yyyy-MM-dd HH:mm"));
        }
        if (!StringUtils.isEmpty(workOrderDetailsModel.getEndTime())) {
            tvOrderServiceSuccessTime.setText(TimeUtils.timeStamp2Date(workOrderDetailsModel.getConstructionStopTime(), "yyyy-MM-dd HH:mm"));
        } else {
            linearOrderServiceSuccessTime.setVisibility(View.GONE);
        }
        tvOrderCar.setText(workOrderDetailsModel.getLicenseNumber() + " " + workOrderDetailsModel.getChName());
        tvOrderCommodityProject.setText(workOrderDetailsModel.getOrderItemNameStr());

        tvOrderTime.setText(workOrderDetailsModel.getConvertServiceTime());
        tvOrderCustomCommodityProject.setText(workOrderDetailsModel.getAllCustomName());
        tvOrderMeassage.setText(StringUtils.getString(workOrderDetailsModel.getNote(), "无"));
        tvStoreName.setText(workOrderDetailsModel.getStoreName());
        //服务中

        if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.INSERVICE)) {
            linearOrderServiceSuccessTime.setVisibility(View.GONE);
            linearOrderCustomCommodityProject.setVisibility(View.GONE);
            //待付余款
        } else if (workOrderDetailsModel.getOrderStatus().equals(OrderDetailsActivity3.INSETTLEMENT)) {

        }
    }

    @Override
    protected void updateViews() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
